<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Dcat\Admin\Traits\ModelTree;

class ArticleCategory extends Model
{
	use HasDateTimeFormatter,ModelTree;
    protected $table = 'article_categories';

    protected $orderColumn = 'sort';

    protected $titleColumn = 'name';

    public function article()
    {
        return $this->hasMany(Article::class,'category_id');
    }

    public static function getOption()
    {
        $category = static::query()
            ->where('status',1)
            ->where('type',2)
            ->get(['id','name']);

        if ($category->isEmpty()){
            return [];
        }

        $options = [];

        foreach ($category as $value){
            $options[$value->id] = $value->name;
        }


        return  $options;

    }


}
